package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsPunishmentMapper;
import net.anzhuo.entity.GsPunishment;
import net.anzhuo.service.GsPunishmentService;
@Service
public class GsPunishmentServiceImpl implements GsPunishmentService {

	@Autowired
	private GsPunishmentMapper gsPunishmentMapper;
	
	@Override
	public GsPunishment getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsPunishmentMapper.getById(id);
	}

	@Override
	public List<GsPunishment> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsPunishmentMapper.getByCoMd5(coMd5);
	}
	
	@Override
	public List<GsPunishment> getByUpdateTime(GsPunishment gs) {
		// TODO Auto-generated method stub
		return gsPunishmentMapper.getByUpdateTime(gs);
	}

	@Override
	public PaginationVO<GsPunishment> getListWithPage(GsPunishment gsPunishment) {
		PaginationVO<GsPunishment> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsPunishmentMapper.getListWithPage(gsPunishment));
		paginationVO.setTotalCount(gsPunishmentMapper.getCount(gsPunishment.getCoMd5()));
		paginationVO.setTotalPage((gsPunishmentMapper.getCount(gsPunishment.getCoMd5()) + gsPunishment.getPageSize() -1)  / gsPunishment.getPageSize()+1);
		paginationVO.setPageNo(gsPunishment.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsPunishment> getList() {
		// TODO Auto-generated method stub
		return  gsPunishmentMapper.getList();
	}

	@Override
	public List<GsPunishment> getList(GsPunishment gsPunishment) {
		// TODO Auto-generated method stub
		return gsPunishmentMapper.getListByQuery(gsPunishment);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsPunishment gsPunishment) {
		// TODO Auto-generated method stub
		gsPunishmentMapper.update(gsPunishment);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsPunishment gsPunishment) {
		// TODO Auto-generated method stub
		gsPunishmentMapper.save(gsPunishment);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsPunishment gsPunishment = gsPunishmentMapper.getById(id);
		if (gsPunishment == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsPunishmentMapper.update(gsPunishment);

	}

}
